#cross compile tool
#ARM_PREFIX=
#ifdef HIS
	#ARM_PREFIX=arm-hisiv500-linux-
#else 
	#ifdef ARM	 
	#ARM_PREFIX=arm-linux-gnueabihf-
	#endif
#endif
ARM_PREFIX=arm-linux-gnueabihf-
CC=$(ARM_PREFIX)gcc
CPP=$(ARM_PREFIX)g++

TARGET = ./bwfcgi
DEBUG_TARGET = ./bwfcgi_g

CSOURCES = 
CPPSOURCES = 

COMMSRC=../common
CPPSOURCES += $(wildcard $(COMMSRC)/*.cpp)
CSOURCES += $(wildcard $(COMMSRC)/*.c)

SRC = ./src
CPPSOURCES += $(wildcard $(SRC)/*.cpp)
CSOURCES += $(wildcard $(SRC)/*.c)

MOD = ./src/mod
CPPSOURCES += $(wildcard $(MOD)/*.cpp)
CSOURCES += $(wildcard $(MOD)/*.c)

UTILS = ./cgiutils
CPPSOURCES += $(wildcard $(UTILS)/*.cpp)
CSOURCES += $(wildcard $(UTILS)/*.c)

LIBUSRC=../lib/libunisky/src
CPPSOURCES += $(wildcard $(LIBUSRC)/*.cpp)
CSOURCES += $(wildcard $(LIBUSRC)/*.c)

APP = ../hiapp/src
#CPPSOURCES += $(wildcard $(APP)/*.cpp)
CPPSOURCES += $(wildcard $(APP)/public.cpp $(APP)/enc_shrm.cpp $(APP)/enc_save.cpp)
#CSOURCES += $(wildcard $(APP)/*.c)
#EXCLUDE_APP = $(APP)/main.cpp
#CPPSOURCES := $(filter-out $(EXCLUDE_APP), $(CPPSOURCES))	

ENCODER = ./src/encoder
CPPSOURCES += $(wildcard $(ENCODER)/*.cpp)
CSOURCES += $(wildcard $(ENCODER)/*.c)

#11.29
NETCFG = ./src/sysinit
CPPSOURCES += $(wildcard $(NETCFG)/*.cpp)
CSOURCES += $(wildcard $(NETCFG)/*.c)

COBJS = $(patsubst %.c, %.o, $(CSOURCES))
CPPOBJS = $(patsubst %.cpp, %.o, $(CPPSOURCES))

HEADPATH += ./inc
HEADPATH += ./inc/fcgi
HEADPATH += ./inc/sqlite3
HEADPATH += ./cgiutils
HEADPATH += ./src/mod
HEADPATH += ../lib/libunisky/inc
HEADPATH += ../lib/
HEADPATH += ./src

HEADPATH += ./src/encoder
#11.29
HEADPATH += ./src/sysinit

HEADPATH += ../hiapp/inc
HEADPATH += ../common

INC = $(patsubst %,-I%,$(HEADPATH)) 
#LIB=-L./lib/
LIB=-L./embed 

OPTIM=-O2
DEBUG=-g 
STRIP=-s

CFLAGS = -std=c99 -D_GNU_SOURCE $(DEBUG) $(OPTIM) -Wall $(INC) -DBWFCGI
#CFLAGS = -std=c99 -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS $(DEBUG) $(OPTIM) -Wall $(INC)
CPPFLAGS = -std=gnu++0x $(DEBUG) $(OPTIM) -Wall $(INC) -DBWFCGI 
#CPPFLAGS = -std=gnu++0x -D__STDC_CONSTANT_MACROS $(DEBUG) $(OPTIM) -Wall $(INC) 
	 
#LDFLAGS1 = $(LIB) -lfcgi++ -lfcgi -lsqlite3 -lcjson -lpthread -ldl
LDFLAGS1 = $(LIB) -lfcgi++ -lfcgi -lsqlite3 -lpthread -ldl

LDFLAGS = $(LDFLAGS1)

all:$(TARGET) $(DEBUG_TARGET)

$(TARGET): $(CPPOBJS) $(COBJS)
	$(CPP) $(STRIP) $(CPPOBJS) $(COBJS) \
	$(LDFLAGS) \
	-o $(TARGET) 
	
$(DEBUG_TARGET): $(CPPOBJS) $(COBJS)
	$(CPP) $(CPPOBJS) $(COBJS) \
	$(LDFLAGS) \
	-o $(DEBUG_TARGET) 
	

%.o:%.c 
#%.o:%.c
	$(CC) $(CFLAGS) \
	-c $<  -o $@
	
%.o:%.cpp 
#%.o:%.cpp 
	$(CPP) $(CPPFLAGS) \
	-c $<  -o $@
	
clean: 
	rm -f  $(CPPOBJS) $(COBJS) \
 	$(TARGET) $(DEBUG_TARGET) 
